import { RouteRecordRaw } from 'vue-router'
import HomeView from '@/views/HomeView.vue'
import UserLayout from '@/layouts/UserLayout.vue'
import UserLoginView from '@/views/user/UserLoginView.vue'
import UserRegisterView from '@/views/user/UserRegisterView.vue'
import AdminView from '@/views/AdminView.vue'
import ACCESS_ENUM from '@/access/accessEnum'
import BasicLayout from '@/layouts/BasicLayout.vue'

/**
 * 导航栏菜单页
 */
export const appRouter = [
  { path: '/home', name: '主页', component: HomeView },
  { path: '/test', name: '测试页', component: () => import('../views/TestView.vue') },
  { path: '/book', name: 'CRUD模板', component: () => import('../views/TestView.vue') },
  {
    path: '/admin',
    name: '管理员页面',
    component: AdminView,
    meta: {
      access: ACCESS_ENUM.ADMIN,
    },
  },
]

export const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    component: BasicLayout,
    redirect: '/home',
    children: appRouter,
  },
  {
    path: '/user',
    name: '用户',
    component: UserLayout,
    children: [
      {
        path: '/user/login',
        name: '用户登录',
        component: UserLoginView,
      },
      {
        path: '/user/register',
        name: '用户注册',
        component: UserRegisterView,
      },
    ],
    meta: {
      hideInMenu: true,
    },
  },
  {
    path: '/403',
    name: '无权限',
    component: () => import('@/views/error/403.vue'),
    meta: {
      hideInMenu: true,
    },
  },
  {
    path: '/:pathMatch(.*)*',
    name: '未找到',
    component: () => import('@/views/error/404.vue'),
    meta: {
      hideInMenu: true,
    },
  },
]
